<?php

use Illuminate\Database\Seeder;
use App\Models\Movie;
use App\Models\User;
use Carbon\Carbon;
class MovieCommentsTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $movies = Movie::all();
        $user_ids = User::pluck('id');
        $faker = app(Faker\Generator::class);
        $start = Carbon::now();
        $end = Carbon::create('-1 year');
        $movies->each(function ($movie) use ($user_ids, $faker, $start, $end) {
            for($i=0; $i <= rand(20,50); $i++) {
               $created_at = $faker->dateTimeBetween($end, 'now');
                $data[] = [
                    'content' => $faker->text(),
                    'user_id' => $user_ids->random(),
                    'movie_id' => $movie->id,
                    'created_at' => $created_at,
                    'updated_at' => $faker->dateTimeBetween($created_at, 'now'),
                ];
            }
            $movie->comments()->insert($data);
        });
    }
}
